package com.zht.utils;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.SecureRandom;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AESUtil {
    private static final String E_74 = "a88eee426bc2cd92472370cf56566e74";
    public static final String VIPARA = "5203702000400000";
    private static final String CBC_PKCS5_PADDING = "AES/CBC/PKCS5Padding";
    private static final String AES = "AES";
    public static final String CODE_TYPE = "UTF-8";

    public AESUtil() {
    }

    public static String encrypt(String content) {
        if (content != null && !"".equals(content)) {
            try {
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                IvParameterSpec zeroIv = new IvParameterSpec("5203702000400000".getBytes("UTF-8"));
                byte[] byteContent = content.getBytes("UTF-8");
                SecretKeySpec skeySpec = new SecretKeySpec("a88eee426bc2cd92472370cf56566e74".getBytes("UTF-8"), "AES");
                cipher.init(1, skeySpec, zeroIv);
                byte[] result = cipher.doFinal(byteContent);
                return Base64.encode(result);
            } catch (Exception var6) {
                Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, (String)null, var6);
                return null;
            }
        } else {
            return content;
        }
    }

    public static String decrypt(String content) {
        if (content != null && !"".equals(content)) {
            System.out.println(content);

            try {
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                IvParameterSpec zeroIv = new IvParameterSpec("5203702000400000".getBytes("UTF-8"));
                SecretKeySpec skeySpec = new SecretKeySpec("a88eee426bc2cd92472370cf56566e74".getBytes("UTF-8"), "AES");
                cipher.init(2, skeySpec, zeroIv);
                byte[] result = cipher.doFinal(Base64.decode(content));
                return new String(result, "UTF-8");
            } catch (Exception var5) {
                Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, (String)null, var5);
                return null;
            }
        } else {
            return content;
        }
    }

    private static SecretKeySpec getSecretKey(String key) {
        KeyGenerator kg = null;

        try {
            kg = KeyGenerator.getInstance("AES");
            kg.init(128, new SecureRandom(key.getBytes()));
            SecretKey secretKey = kg.generateKey();
            return new SecretKeySpec(secretKey.getEncoded(), "AES");
        } catch (Exception var3) {
            Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, (String)null, var3);
            return null;
        }
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
    }
}